package com.yjd.bi.system.service.impl;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import com.yjd.bi.comm.vo.Constant;
import com.yjd.comm.base.enums.DbWREnums;
import com.yjd.comm.util.FrameUtil;
import org.springframework.stereotype.Service;

import com.yjd.comm.base.dao.IBaseDao;
import com.yjd.comm.base.service.impl.BaseServiceImpl;
import com.yjd.bi.system.model.SysParamModel;
import com.yjd.bi.system.service.ISysParamService;
import com.yjd.bi.system.dao.ISysParamDao;

/**
 * <b>description</b>：系统参数表业务实现<br>
 * <b>time</b>：2018-01-12 09:26:17 <br>
 * <b>author</b>：  yangchangyan@yijiedai.com
 */
@Service("sysParamService")
public class SysParamServiceImpl extends BaseServiceImpl implements ISysParamService {

	/**
	 * 插入
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	public SysParamModel insert(SysParamModel model) throws Exception {
		return this.sysParamDao.insertModel(model, true);
	}

	/**
	 * 更新
	 * 
	 * @param model
	 * @return
	 * @throws Exception
	 */
	public int update(SysParamModel model) throws Exception {
		return this.sysParamDao.updateModel(model, true);
	}

	/**
	 * 根据id删除
	 * 
	 * @param id_param
	 * @return
	 * @throws Exception
	 */
	public int delete(long id_param) throws Exception {
		Map<Object, Object> paramMap = new HashMap<Object, Object>();
		paramMap.put("id_param", id_param);
		return this.sysParamDao.deleteModel(paramMap, true);
	}

	@Override
	public SysParamModel getModelByKey(Constant.SysParamKeyEnum key) throws Exception {
		Map<Object, Object> paramMap = new HashMap<Object, Object>();
		paramMap.put("param_key", key.getKey());
		return this.getModelOne(paramMap, DbWREnums.READ);
	}

	@Override
	public String getValueByKey(Constant.SysParamKeyEnum key) throws Exception {
		Map<Object, Object> paramMap = new HashMap<Object, Object>();
		paramMap.put("param_key", key.getKey());
		SysParamModel model = this.getModelOne(paramMap, DbWREnums.READ);
		if(null == model){
			FrameUtil.throwBaseException1("查询不到key:"+key.getKey());
		}
		return model.getParam_value();
	}

	@Resource
	private ISysParamDao sysParamDao;

	@Override
	public IBaseDao getBaseDao() {
		return this.sysParamDao;
	}

}
